package com.littlec.sdk.utils;

import org.jivesoftware.smack.XMPPConnection;

import com.littlec.sdk.XMPPConnectionManager;
import com.littlec.sdk.manager.CMIMHelper;

public class SdkUtils {
	private static final String TAG = "SdkUtils";
	public static final MyLogger sLogger = MyLogger.getLogger("SdkUtils");

	public static void addListeners(CMContactListener contactlistener,
			CMChatListener.CMMessageReceivedCallBack messageReceivedCallBack)
			throws NullPointerException {
		XMPPConnection connection = XMPPConnectionManager.getInstance()
				.getConnection();
		if (connection == null)
			throw new NullPointerException("请在登录成功后，再调用消息监听接口");
		if (messageReceivedCallBack != null) {
			CMIMHelper.getCmMessageManager().addMessageListener(
					messageReceivedCallBack);
		}
		if (contactlistener != null) {
			CMIMHelper.getCmContactManager()
					.setContactListener(contactlistener);
		}
		XMPPConnectionManager.getInstance().setListenerAdded(true);
		XMPPConnectionManager.getInstance().sendOnlinePacket();
	}

	// ��֤�û���Ϸ���Ϣ
	public static boolean checkUserName(String userName) {
		if (userName == null) {
			return false;
		}
		return userName.matches("[0-9A-Za-z_]{1,50}$");
	}
}
